package com.manage.web;

import com.manage.pojo.UserBase;
import com.manage.pojo.UserDetails;
import com.manage.pojo.UserExtensions;
import com.manage.pojo.UserSms;
import com.manage.result.Result;
import com.manage.service.UserService;
import com.manage.service.UserSmsService;
import com.manage.vo.UserVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;
    @Autowired
    UserSmsService mUserSmsService;

    @PostMapping("save")
    public ResponseEntity<Void> saveUser(UserBase userBase, UserDetails userDetails, UserExtensions userExtensions) {
        userService.saveUser(userBase, userDetails, userExtensions);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    //todo:后面更新操作或者删除以及登录操作要用POST 不能用GET请求
    @GetMapping("update")
    public ResponseEntity<Void> updateUser(UserBase userBase, UserDetails userDetails, UserExtensions userExtensions) {
        userService.updateUser(userBase, userDetails, userExtensions);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    //todo:测试过程中用get请求后面写好之后用POST
    @GetMapping("select/{jobNumber}")
    public ResponseEntity<UserVo> selectUser(@Param("jobNumber") Long jobNumber) {
        return ResponseEntity.ok(userService.selectUser(jobNumber));
    }

    //todo:后面更新操作或者删除以及登录操作要用POST 不能用GET请求
//    @PostMapping("delete")
    @GetMapping("delete")
    @ResponseBody
    public Result deleteUser(Long jobNumber) {
        return userService.deleteUser(jobNumber);
    }

    //测试过程中用get请求后面写好之后用POST
//    @GetMapping("/passwordLogin")
    @PostMapping("/passwordLogin")
    @ResponseBody
    public Result<UserVo> passwordLogin(String mobilePhone, String password) {
        return userService.passwordLogin(mobilePhone, password);
    }

//    @PostMapping("/fastLogin")
    @GetMapping("/fastLogin")
    @ResponseBody
    public Result<UserVo> fastLogin(String mobilePhone, long smsType, String smsCode) {
        return userService.fastLogin(mobilePhone, smsType, smsCode);
    }

    @PostMapping("/sendSMS")
    @ResponseBody
    public Result<UserSms> sendSMS(String mobilePhone, long smsType) {
        return mUserSmsService.sendSMS(mobilePhone, smsType);
    }
}
